package org.example;

import java.util.*;

public class Collection {
    public static void main(String[] args) {
        //ArrayList-数组-查询效率高
        //LinkedList-链表-增删效率高
        //Vector-数组-线程安全
        Map<Integer,String> map=new HashMap<>();
        //HashMap 线程不安全 效率高  允许key和value为null
        //HashTable 线程安全 效率低 不允许key或value为null
        map.put(1,"1");
        map.put(2,"2");
        map.put(3,"3");
        map.put(4,"4");
        map.put(5,"5");
        List<String> list=new ArrayList<>();
        list.add("222");
        list.add("222");
        list.add("222");
        list.add("222");
        list.add("222");
        list.add("222");
        list.set(0,"2");
        for(Iterator<String> iterable = list.iterator();iterable.hasNext();){
            System.out.println(iterable.next());
        }
        Set<Map.Entry<Integer,String>> mapSet=map.entrySet();
        for(Iterator<Map.Entry<Integer,String>> iterable = mapSet.iterator(); iterable.hasNext();){
            Map.Entry<Integer,String> entry=iterable.next();
            System.out.println(entry.getKey()+"  :  "+entry.getValue());
        }
        Set<Integer> keySet=map.keySet();
        for(Iterator<Integer> iterable = keySet.iterator(); iterable.hasNext();){
            Integer key=iterable.next();
            System.out.println(map.get(key)+"  :  "+key);
            iterable.remove();
        }
    }
    public static void Collections(){
        //辅助类的使用

        List<String> list=new ArrayList<>();
        Collections.shuffle(list);//随机打乱
        Collections.reverse(list);
        Collections.sort(list);
        Collections.binarySearch(list,"66");
    }
    public static void List(){
        //可以使用索引 set get remove 使用下标 indexOf
    }
    public static void Collection(){
        java.util.Collection<String> collection=new ArrayList<String>();
        collection.size();
        collection.isEmpty();
        collection.add("11");
        collection.add("22");
        collection.add("33");
        collection.add("44");
        collection.add("55");
        collection.add("66");
        collection.contains("11");
        collection.remove("66");
        collection.clear();
        Object[] strings=collection.toArray();
        collection.contains("66");

        java.util.Collection<String> other=new ArrayList<String>();
        other.addAll(collection);
        other.removeAll(collection);
        other.retainAll(collection);
        other.containsAll(collection);
    }
}
